<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="原文件名称" prop="originalFileName">
        <el-input
          v-model="queryParams.originalFileName"
          placeholder="请输入原文件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="新文件名称" prop="newFileName">
        <el-input
          v-model="queryParams.newFileName"
          placeholder="请输入新文件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:file:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:file:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:file:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:file:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-up"
          size="mini"
          @click="uploadFileHandle"
        >上传文件
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="createPdfHandle"
        >生成
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="showCreatFormOne"
        >提交
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fileList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="原文件名称" align="center" prop="originalFileName"/>
      <el-table-column label="原始文件所在路径" align="center" prop="originalFilePath"/>
      <el-table-column label="新文件名称" align="center" prop="newFileName"/>
      <el-table-column label="新文件所在路径" align="center" prop="newFilePath"/>
      <el-table-column label="文件归属人" align="center" prop="userName"/>
      <el-table-column label="文件归属功能" align="center" prop="assistTypeName"/>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="备注信息" align="center" prop="remarks"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEdit(scope.row.id)"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:file:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 前置信息填写 -->
    <el-dialog title="前置信息设置" :visible.sync="openCreateFormOneFlag" width="60%" append-to-body>
      <el-form :model="createForm" ref="createForm" size="small" :inline="true" label-width="100px">
        <el-form-item label="类型" prop="typeId">
          <el-input
            v-model="createForm.typeId"
            placeholder="请输入类型"
            clearable
          />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-input
            v-model="createForm.startTime"
            placeholder="请输入开始时间"
            clearable
          />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-input
            v-model="createForm.endTime"
            placeholder="请输入结束时间"
            clearable
          />
        </el-form-item>
        <el-form-item label="户名" prop="userName">
          <el-input
            v-model="createForm.userName"
            placeholder="请输入户名"
            clearable
          />
        </el-form-item>
        <el-form-item label="账户号" prop="accountNo">
          <el-input
            v-model="createForm.accountNo"
            placeholder="请输入账户号"
            clearable
          />
        </el-form-item>
        <el-form-item label="电子流水号" prop="serialNo">
          <el-input
            v-model="createForm.serialNo"
            placeholder="请输入电子流水号"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="showCreatFormTwo">确定</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="openCreateFormOneFlag = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 明细生成回填 -->
    <el-dialog title="明细生成回填" :visible.sync="openCreateFormTwoFlag" width="75%" append-to-body>
      <div>
        <el-form ref="createFormTwo" :model="createForm" label-width="120px">
          <el-form-item label="原始余额：" prop="originalMoney" style="float: left">
            <el-input v-model="createForm.originalMoney" placeholder="请输入原始余额"/>
          </el-form-item>
          <el-form-item label="明细总条数：" prop="detailNums" style="float: left">
            <el-input v-model="createForm.detailNums" placeholder="请输入明细总条数"/>
          </el-form-item>
          <el-form-item label="收入总条数：" prop="inNum" style="float: left">
            <el-input v-model="createForm.inNum" placeholder="请输入收入总条数"/>
          </el-form-item>
          <el-form-item label="总金额(收)：" prop="totalInMoney" style="float: left">
            <el-input v-model="createForm.totalInMoney" placeholder="请输入总金额(收)"/>
          </el-form-item>
          <el-form-item label="总金额(支)：" prop="totalOutMoney" style="float: left">
            <el-input v-model="createForm.totalOutMoney" placeholder="请输入总金额(支)"/>
          </el-form-item>
          <el-button type="primary" style="margin-left: 15px" @click="createAndShow(createForm)">生成且回填
          </el-button>
          <div style="clear: both"></div>
          <div
            v-if="randomData.inValueList != undefined && randomData.inValueList != null && randomData.inValueList.length > 0">
            <span>处理后总额(收)：<span style="color: green; margin-right: 10px">{{ randomData.dealInTotalMoney }};</span> </span>
            <span>处理后总额(支)：<span style="color: red; margin-right: 10px">{{ randomData.dealOutTotalMoney }};</span> </span>
            <span>差值：<span style="color: orange">{{ randomData.dealInTotalMoney - randomData.dealOutTotalMoney }};</span> </span>
          </div>
        </el-form>
      </div>
      <div style="margin-top: 8px">
        <el-tabs v-model="activeName" tab-position="top" type="border-card" @tab-click="handleClick">
          <el-tab-pane :label="'收入明细 (' + randomData.inValueList.length + ')'" name="in">
            <el-table v-loading="editLoading" :data="randomData.inValueList" :cell-class-name="tableCellClassName"
                      @row-dblclick="dbclick">
              <el-table-column label="交易日期" align="center" prop="transactionDate">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionDate"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionDate }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易时间" align="center" prop="transactionTime">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionTime"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionTime }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易摘要" align="center" prop="transactionDesc">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionDesc"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionDesc }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易金额" align="center" prop="transactionMoneyInt">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionMoneyInt"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionMoneyInt }}</span>
                </template>
              </el-table-column>
              <el-table-column label="对手信息" align="center" prop="oppositionInfo">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.oppositionInfo"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.oppositionInfo }}</span>
                </template>
              </el-table-column>
              <el-table-column label="日志号" align="center" prop="logNo">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.logNo"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.logNo }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易渠道" align="center" prop="tradingChannels">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.tradingChannels"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.tradingChannels }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易附言" align="center" prop="transactionNote">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionNote"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionNote }}</span>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane :label="'支出明细 (' + randomData.outValueList.length + ')'" name="out">
            <el-table v-loading="editLoading" :data="randomData.outValueList" :cell-class-name="tableCellClassName"
                      @row-dblclick="dbclick">
              <el-table-column label="交易日期" align="center" prop="transactionDate">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionDate"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionDate }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易时间" align="center" prop="transactionTime">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionTime"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionTime }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易摘要" align="center" prop="transactionDesc">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionDesc"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionDesc }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易金额" align="center" prop="transactionMoneyInt">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionMoneyInt"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionMoneyInt }}</span>
                </template>
              </el-table-column>
              <el-table-column label="对手信息" align="center" prop="oppositionInfo">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.oppositionInfo"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.oppositionInfo }}</span>
                </template>
              </el-table-column>
              <el-table-column label="日志号" align="center" prop="logNo">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.logNo"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.logNo }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易渠道" align="center" prop="tradingChannels">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.tradingChannels"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.tradingChannels }}</span>
                </template>
              </el-table-column>
              <el-table-column label="交易附言" align="center" prop="transactionNote">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.transactionNote"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.transactionNote }}</span>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dealRandomDataToFile">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改文件记录对话框 -->
    <el-dialog :title="title" :visible.sync="openCreatePdfFlag" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="PDF文件id" prop="typeId">
          <el-input v-model="form.typeId" placeholder="PDF文件id"/>
        </el-form-item>
        <el-form-item label="生成明细总条数" prop="detailNums">
          <el-input v-model="form.detailNums" placeholder="请输入生成明细总条数"/>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-input v-model="form.startTime" placeholder="请输入开始时间"/>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-input v-model="form.endTime" placeholder="请输入结束时间"/>
        </el-form-item>
        <el-form-item label="原始余额" prop="originalMoney">
          <el-input v-model="form.originalMoney" placeholder="请输入原始余额"/>
        </el-form-item>
        <el-form-item label="收入总条数" prop="inNum">
          <el-input v-model="form.inNum" placeholder="请输入收入总条数"/>
        </el-form-item>
        <el-form-item label="收入总金额" prop="totalInMoney">
          <el-input v-model="form.totalInMoney" placeholder="请输入收入总金额"/>
        </el-form-item>
        <el-form-item label="支出总金额" prop="totalOutMoney">
          <el-input v-model="form.totalOutMoney" placeholder="请输入支出总金额"/>
        </el-form-item>
        <el-form-item label="户名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入户名"/>
        </el-form-item>
        <el-form-item label="账户(17位)" prop="accountNo">
          <el-input v-model="form.accountNo" placeholder="请输入账户(17位)"/>
        </el-form-item>
        <el-form-item label="电子流水号(19位)" prop="serialNo">
          <el-input v-model="form.serialNo" type="textarea" placeholder="请输入电子流水号(19位)"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPdfForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 随机数回显对话框 -->
    <el-dialog title="随机数生成回填" :visible.sync="editOpen" width="75%" append-to-body>
      <div>
        <el-form ref="randomForm" :model="originalData" label-width="80px">
          <el-form-item label="收入：" prop="originalFileName" style="float: left">
            <el-input v-model="originalData.desireInMoney" placeholder="请输入期望收入金额"/>
          </el-form-item>
          <el-form-item label="支出：" prop="originalFilePath" style="float: left">
            <el-input v-model="originalData.desireOutMoney" placeholder="请输入期望支出金额"/>
          </el-form-item>
          <el-button type="primary" style="margin-left: 15px" @click="createRondomValue(originalData)">生成随机数
          </el-button>
          <div style="clear: both"></div>
          <div
            v-if="dealData.inDealRecord != undefined && dealData.inDealRecord != null && dealData.inDealRecord.length > 0">
            <span>原始收总额：<span style="color: #7a6df0">{{ dealData.originalInTotalMoney }};</span> </span>
            <span>原始支总额：<span style="color: #7a6df0">{{ dealData.originalOutTotalMoney }};</span> </span>
            <span>处理后收总额：<span style="color: #42b983">{{ dealData.dealInTotalMoney }};</span> </span>
            <span>处理后支总额：<span style="color: #42b983">{{ dealData.dealOutTotalMoney }};</span> </span>
          </div>
        </el-form>
      </div>
      <div style="margin-top: 8px">
        <el-tabs v-model="activeName" tab-position="top" type="border-card" @tab-click="handleClick">
          <el-tab-pane :label="'收入明细 (' + dealData.dealInTotalSize + ')'" name="in">
            <el-table v-loading="editLoading" :data="dealData.inDealRecord" :cell-class-name="tableCellClassName"
                      @row-dblclick="dbclick">
              <el-table-column label="交易名称" align="center" prop="name"/>
              <el-table-column label="交易类型" align="center" prop="type"/>
              <el-table-column label="交易方式" align="center" prop="way"/>
              <el-table-column label="原始金额" align="center" prop="money"/>
              <el-table-column label="处理后金额" align="center" prop="dealMoney">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.dealMoney"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.dealMoney }}</span>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane :label="'支出明细 (' + dealData.dealOutTotalSize + ')'" name="out">
            <el-table v-loading="editLoading" :data="dealData.outDealRecord" :cell-class-name="tableCellClassName"
                      @row-dblclick="dbclick">
              <el-table-column label="交易名称" align="center" prop="name"/>
              <el-table-column label="交易类型" align="center" prop="type"/>
              <el-table-column label="交易方式" align="center" prop="way"/>
              <el-table-column label="原始金额" align="center" prop="money"/>
              <el-table-column label="处理后金额" align="center" prop="dealMoney">
                <template slot-scope="scope">
                  <el-input
                    v-if="scope.row.index + ',' + scope.column.index == currentCell"
                    :ref="scope.row.index + ',' + scope.column.index"
                    v-model="scope.row.dealMoney"
                    @blur="hideInput(scope.row)"
                  />
                  <span v-else>{{ scope.row.dealMoney }}</span>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dealDataToFile">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 文件上传模态框 -->
    <el-dialog title="文件上传" :visible.sync="uploadFileBox" width="30%">
      <div class="uploadBox">
        <div style="margin-bottom: 15px">
          功能类型：
          <el-select
            v-model="typeId"
            placeholder="请选择功能类型"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="type in assistTypeList"
              :key="type.id"
              :label="type.functionName"
              :value="type.id"
            />
          </el-select>
        </div>
        <!-- 1.将<el-upload>代码添加到<el-dialog>代码块中 -->
        <div>
          <el-upload
            ref="upload"
            class="upload-demo"
            :before-upload="uploadBefore"
            drag
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            <div class="el-upload__tip" slot="tip">
              <span style="font-size: 11px; color: red">Tip: 只能上传<span style="color: orange">PDF</span>文件</span>
            </div>
          </el-upload>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listFile,
  getFile,
  delFile,
  addFile,
  updateFile,
  getOriginalDataByFileId,
  createRomValueMapping, dealPdfToFile, uploadPdfFile, getAssistTypeList,
  createPdfFile,
  getDealedValueList,
  createFileByData
} from "@/api/system/file";

export default {
  name: "File",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文件记录表格数据
      fileList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      editOpen: false,
      createForm: {
        typeId: null,
        detailNums: null,
        startTime: null,
        endTime: null,
        originalMoney: null,
        inNum: null,
        totalInMoney: null,
        totalOutMoney: null,
        userName: null,
        accountNo: null,
        serialNo: null,
        inValueList: [],
        outValueList: [],
      },
      openCreateFormOneFlag: false,
      openCreateFormTwoFlag: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        originalFileName: null,
        newFileName: null,
        userId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      originalData: {},
      dealData: {},
      randomData: {
        inValueList: [],
        outValueList: [],
        dealInTotalMoney: 0,
        dealOutTotalMoney: 0
      },
      editLoading: false,
      activeName: 'in',
      currentCell: null,
      uploadFileBox: false,
      typeId: null,
      assistTypeList: [],
      openCreatePdfFlag: false
    };
  },
  created() {
    this.getList();
    this.getAssistTypeList();
  },
  methods: {
    /** 查询文件记录列表 */
    getList() {
      this.loading = true;
      listFile(this.queryParams).then(response => {
        this.fileList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getAssistTypeList() {
      getAssistTypeList().then(res => {
        this.assistTypeList = res.data;
      })
    },
    // 取消按钮
    cancel() {
      this.openCreateFormTwoFlag = false;
    },
    // 表单重置
    reset() {
      this.form = {
        typeId: null,
        detailNums: null,
        startTime: null,
        endTime: null,
        originalMoney: null,
        inNum: null,
        totalInMoney: null,
        totalOutMoney: null,
        userName: null,
        accountNo: null,
        serialNo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加文件记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFile(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改文件记录";
      });
    },
    uploadFileHandle() {
      this.uploadFileBox = true;
    },
    uploadBefore(file) {
      if (this.typeId != null && this.typeId != undefined) {
        const fileData = new FormData();
        fileData.append('file', file);
        // 添加自定义数据
        fileData.append('assistTypeId', this.typeId);
        return uploadPdfFile(fileData).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("文件上传成功！");
            this.getList();
            this.uploadFileBox = false;
          } else {
            this.$modal.msgError("文件上传失败:" + res.msg);
          }
        });
      } else {
        this.$modal.msgWarning("功能类型不能为空！");
      }
    },
    /** 编辑按钮操作 */
    handleEdit(id) {
      this.dealData = {
        inDealRecord: [],
        outDealRecord: [],
        dealInTotalSize: 0,
        dealOutTotalSize: 0
      };
      const loading = this.$loading({
        lock: true,
        text: '加载中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      getOriginalDataByFileId(id).then(response => {
        this.originalData = response.data;
        this.editOpen = true;
        loading.close();
      });
    },
    // 生成随机数并映射
    createRondomValue(originalData) {
      this.editLoading = true;
      createRomValueMapping(originalData).then(res => {
        this.dealData = res.data;
        this.editLoading = false;
      })
    },
    handleClick(tab, event) {
      console.log(tab, event);
      this.activeName = tab.name;
      this.hideInput(this.randomData.inValueList[0]);
      this.hideInput(this.randomData.outValueList[0]);
    },
    // 给单元格绑定横向和竖向的index，这样就能确定是哪一个单元格
    tableCellClassName({row, column, rowIndex, columnIndex}) {
      row.index = rowIndex
      column.index = columnIndex
    },
    // 获得当前双击的单元格的横竖index，然后拼接成一个唯一字符串用于判断，并赋给currentCell
    // 拼接后类似这样："1,0","1,1",
    dbclick(row, column) {
      this.currentCell = row.index + ',' + column.index
      // input 自动获取焦点
      // 双击后自动获得焦点
      this.$nextTick(() => {
        this.$refs[row.index + ',' + column.index].focus();
      })
      /*if (column.property === 'transactionMoneyInt') {

      }*/
    },
    // 关闭编辑状态
    hideInput(row) {
      this.currentCell = null
      this.calcTotalMoney();
    },
    dealDataToFile() {
      dealPdfToFile(this.dealData).then(res => {
        if (res.code === 200) {
          this.$modal.msgSuccess("文件处理成功！");
          this.openDownLoadBox(res.data.id);
        } else {
          this.$modal.msgError("文件处理失败！");
        }
      })
    },
    openDownLoadBox(fileId) {
      this.$confirm('点击下载文件', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'success'
      }).then(() => {
        this.downLoadFile(fileId);
      });
    },
    calcTotalMoney() {
      let inTotal = this.randomData.inValueList.reduce((sum, e) => sum + Number(e.transactionMoneyInt || 0), 0);
      let outTotal = this.randomData.outValueList.reduce((sum, e) => sum + Number(e.transactionMoneyInt || 0), 0);
      this.$set(this.randomData, 'dealInTotalMoney', inTotal);
      this.$set(this.randomData, 'dealOutTotalMoney', Math.abs(outTotal));
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFile(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFile(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除文件记录编号为"' + ids + '"的数据项？').then(function () {
        return delFile(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/file/export', {
        ...this.queryParams
      }, `file_${new Date().getTime()}.xlsx`)
    },
    // 下载处理完成的文件
    downLoadFile(fileId) {
      this.$download.downloadDealFile(fileId).then(res => {
        this.$modal.msgSuccess("文件下载中,请稍等...");
      })
    },
    // 创建PDF文件按钮
    createPdfHandle(){
      this.openCreatePdfFlag = true;
    },
    submitPdfForm() {
      createPdfFile(this.form).then(res => {
        console.log('创建PDF文件...');
        console.log(res);
      })
    },
    showCreatFormOne() {
      this.openCreateFormOneFlag = true;
    },
    showCreatFormTwo() {
      // 校验必填是否为空，
      this.openCreateFormTwoFlag = true;
      this.openCreateFormOneFlag = false;
    },
    createAndShow(row) {
      getDealedValueList(row).then(res => {
        this.randomData = res.data;
        this.hideInput(this.randomData.inValueList[0]);
        this.hideInput(this.randomData.outValueList[0]);
      })
    },
    dealRandomDataToFile() {
      this.$set(this.createForm, 'inValueList', this.randomData.inValueList);
      this.$set(this.createForm, 'outValueList', this.randomData.outValueList);
      createFileByData(this.createForm).then(res => {
        if (res.code === 200) {
          this.$modal.msgSuccess("文件处理成功！");
          // this.openDownLoadBox(res.data.id);
        } else {
          this.$modal.msgError("文件处理失败！");
        }
      })
    }
  }
};
</script>

<style>
.uploadBox {
  display: grid;
  place-items: center;
}
</style>
